//  [10/14/2013 OMEGA] created

#ifndef _DUELGUIEGRAPHICSVIEW_H_
#define _DUELGUIEGRAPHICSVIEW_H_


#include <QtWidgets/QtWidgets>
#include "DuelGUIECommon.h"
#include "DuelRenderWindow.h"
#include "DuelFrameBuffer.h"

class DGUIEGraphicsViewEventHandler
{
public:
	virtual void	handleMousePressEvent(QMouseEvent* e) {}
	virtual	void	handleMouseReleaseEvent(QMouseEvent* e) {}
	virtual	void	handleMouseMoveEvent(QMouseEvent* e) {}
	virtual void	handleWheelEvent(QWheelEvent* e) {}
	virtual void	handleKeyPressEvent(QKeyEvent* e) {}
	virtual void	handleKeyReleaseEvent(QKeyEvent* e) {}
};

class DGUIEGraphicsRenderHandler
{
public:
	virtual void	render(Duel::DFrameBuffer* target) = 0;
};

class DGUIEGraphicsView : public QWidget
{
	Q_OBJECT
public:
	DGUIEGraphicsView(const QString& name, 
		DGUIEGraphicsRenderHandler* renderHandler, 
		DGUIEGraphicsViewEventHandler* eventHandler,
		QWidget* parent = 0);
	~DGUIEGraphicsView();

	void			update()
	{
		if (mRenderHandler)
		{
			mRenderHandler->render(mRenderWindow);
			mRenderWindow->update();
		}
		
	}

	bool			isFocused() { return mbFocused; }

protected:
	// override : QWidget---------
	void			mousePressEvent(QMouseEvent* e);
	void			mouseReleaseEvent(QMouseEvent* e);
	void			mouseMoveEvent(QMouseEvent* e);
	void			wheelEvent(QWheelEvent* e);
	void			keyPressEvent(QKeyEvent* e);
	void			keyReleaseEvent(QKeyEvent* e);

	QPaintEngine*	paintEngine() const
	{ 
		return NULL;
	} 

	virtual void    paintEvent(QPaintEvent *e);

	virtual void    resizeEvent(QResizeEvent *p_event);

	// a flag indicating whether this view is focused.
	bool			mbFocused;

	Duel::DRenderWindow*	mRenderWindow;
	QString					mName;
	DGUIEGraphicsRenderHandler*	mRenderHandler;
	DGUIEGraphicsViewEventHandler*	mEventHandler;

};

#endif